package com.lmiot.xyclick.Notic;

import android.content.Context;
import android.content.SharedPreferences;
import com.lmiot.floatviewsdklibrary.SDK.YYFloatButton;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Auto.AutoTypeEnum;
import com.lmiot.xyclick.Auto.AutoUtils;
import com.lmiot.xyclick.Bean.DoAutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lmiot.xyclick.Bean.TimerBean;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.Util.AlarmUtil;
import com.lmiot.xyclick.Util.TimeUtils;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionAsSDK;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.SDK.SDK;
import com.yhao.floatwindow.FloatUtil;
import com.youyi.yynoticlibrary.YYNoticSDK;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import java.util.List;
import org.greenrobot.eventbus.EventBus;

public class NoticManager {
    private static final NoticManager ourInstance = new NoticManager();

    public static NoticManager getInstance() {
        return ourInstance;
    }

    private NoticManager() {
    }

    public void show(final NoticEnum noticEnum) {
        setNoticValue(MyApp.getContext(), noticEnum, true);
        int i = noticEnum.ordinal();
        if (i == 1) {
            YYNoticSDK.getInstance().view(MyApp.getContext(), noticEnum.getNoticID(), R.layout.item_notic_float, R.drawable.icon_small, false, false, new YYNoticSDK.OnRemoteViewClickListener() {
                /* class com.lmiot.xyclick.Notic.NoticManager.AnonymousClass1 */

                @Override // com.youyi.yynoticlibrary.YYNoticSDK.OnRemoteViewClickListener
                public void click(int i, int i2) {
                    if (i2 != R.id.id_img_switch) {
                        if (i2 == R.id.id_notic_exit) {
                            NoticManager.setNoticValue(MyApp.getContext(), noticEnum, false);
                            YYNoticSDK.getInstance().cancelNotic(MyApp.getContext(), i);
                        }
                    } else if (FloatUtil.getShowFlow(MyApp.getContext())) {
                        FloatUtil.setShowFlow(MyApp.getContext(), false);
                        YYNoticSDK.getInstance().setImageViewResource(i, R.id.id_img_switch, R.drawable.switch_off);
                        YYFloatButton.hide();
                    } else {
                        YYFloatButton.show(MyApp.getContext());
                        FloatUtil.setShowFlow(MyApp.getContext(), true);
                        YYNoticSDK.getInstance().setImageViewResource(i, R.id.id_img_switch, R.drawable.switch_on);
                    }
                }
            }, R.id.id_img_switch, R.id.id_notic_exit);
            YYNoticSDK.getInstance().setImageViewResource(noticEnum.getNoticID(), R.id.id_img_switch, FloatUtil.getShowFlow(MyApp.getContext()) ? R.drawable.switch_on : R.drawable.switch_off);
        } else if (i == 2) {
            YYNoticSDK.getInstance().view(MyApp.getContext(), noticEnum.getNoticID(), R.layout.item_notic_running, R.drawable.icon_small, false, false, new YYNoticSDK.OnRemoteViewClickListener() {
                /* class com.lmiot.xyclick.Notic.NoticManager.AnonymousClass2 */

                @Override // com.youyi.yynoticlibrary.YYNoticSDK.OnRemoteViewClickListener
                public void click(int i, int i2) {
                    if (i2 == R.id.id_main || i2 == R.id.id_notic_exit) {
                        NoticManager.setNoticValue(MyApp.getContext(), noticEnum, false);
                        YYNoticSDK.getInstance().cancelNotic(MyApp.getContext(), i);
                        SDK.isRunning = false;
                        EventBus.getDefault().post(new DoAutoBean(104, null, null, 0));
                    }
                }
            }, R.id.id_main, R.id.id_notic_exit);
        }
    }

    public void hide(NoticEnum noticEnum) {
        setNoticValue(MyApp.getContext(), noticEnum, false);
        YYNoticSDK.getInstance().cancelNotic(MyApp.getContext(), noticEnum.getNoticID());
    }

    public static void setNoticValue(Context context, NoticEnum noticEnum, boolean z) {
        SharedPreferences.Editor edit = context.getSharedPreferences("NoticManager", 0).edit();
        edit.putBoolean("setNoticValue" + noticEnum.toString(), z).commit();
    }

    public static boolean getNoticValue(Context context, NoticEnum noticEnum) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("NoticManager", 0);
        return sharedPreferences.getBoolean("setNoticValue" + noticEnum.toString(), false);
    }

    public void updateAutoNotic() {
        for (AutoBean autoBean : AutoBeanSqlUtil.getInstance().searchAll()) {
            YYNoticSDK.getInstance().cancelNotic(MyApp.getContext(), TimeUtils.getNoticID(autoBean.getAutoID()));
        }
        for (final AutoBean autoBean2 : AutoBeanSqlUtil.getInstance().searchAllByShowNotic()) {
            int noticID = TimeUtils.getNoticID(autoBean2.getAutoID());
            String autoType = autoBean2.getAutoType();
            YYNoticSDK.getInstance().view(MyApp.getContext(), noticID, R.layout.item_notic_auto, R.drawable.icon_small, false, false, new YYNoticSDK.OnRemoteViewClickListener() {
                /* class com.lmiot.xyclick.Notic.NoticManager.AnonymousClass3 */

                @Override // com.youyi.yynoticlibrary.YYNoticSDK.OnRemoteViewClickListener
                public void click(int i, int i2) {
                    if (i2 == R.id.id_auto_edit) {
                        ActionNormalSDK.getInstance().closeNotification(MyApp.getContext());
                        if (AutoUtils.canEdit(autoBean2)) {
                            AutoUtils.editAuto(MyApp.getContext(), autoBean2);
                        } else {
                            ToastUtil.err("此自动化不能被编辑！");
                        }
                    } else if (i2 == R.id.id_notic_exit) {
                        autoBean2.setShowNotic(false);
                        AutoBeanSqlUtil.getInstance().add(autoBean2);
                        YYNoticSDK.getInstance().cancelNotic(MyApp.getContext(), i);
                    } else if (i2 == R.id.id_play) {
                        ActionNormalSDK.getInstance().closeNotification(MyApp.getContext());
                        if (ActionAsSDK.getInstance().checkAs(MyApp.getContext())) {
                            EventBus.getDefault().post(new DoAutoBean(101, autoBean2, null, 0));
                            return;
                        }
                        ToastUtil.warning(MyApp.getContext().getString(R.string.opfs));
                        ActionNormalSDK.getInstance().gotoAsSetting(MyApp.getContext());
                    }
                }
            }, R.id.id_play, R.id.id_auto_edit, R.id.id_notic_exit);
            if (autoType.equals(AutoTypeEnum.click.toString())) {
                YYNoticSDK.getInstance().setImageViewResource(noticID, R.id.id_play, R.drawable.notic_auto);
                YYNoticSDK.getInstance().setTextViewText(noticID, R.id.id_repeat, MyApp.getContext().getString(R.string.mb22));
                YYNoticSDK.getInstance().setTextViewText(noticID, R.id.id_name, autoBean2.getAutoName());
            } else if (autoType.equals(AutoTypeEnum.time.toString())) {
                YYNoticSDK.getInstance().setImageViewResource(noticID, R.id.id_play, R.drawable.notic_time);
                List<TimerBean> normalTimeToTimeList = AlarmUtil.normalTimeToTimeList(autoBean2.getAutoTypeDetail());
                YYNoticSDK instance = YYNoticSDK.getInstance();
                instance.setTextViewText(noticID, R.id.id_name, normalTimeToTimeList.size() + "组定时");
                YYNoticSDK.getInstance().setTextViewText(noticID, R.id.id_repeat, autoBean2.getAutoName());
            } else if (autoType.equals(AutoTypeEnum.notic.toString()) || autoType.equals(AutoTypeEnum.notic_now.toString())) {
                YYNoticSDK.getInstance().setImageViewResource(noticID, R.id.id_play, R.drawable.notic_text);
                YYNoticSDK instance2 = YYNoticSDK.getInstance();
                instance2.setTextViewText(noticID, R.id.id_name, MyApp.getContext().getString(R.string.mb24) + autoBean2.getAutoTypeDetail());
                YYNoticSDK.getInstance().setTextViewText(noticID, R.id.id_repeat, autoBean2.getAutoName());
            } else if (autoType.equals(AutoTypeEnum.screen.toString()) || autoType.equals(AutoTypeEnum.screen_now.toString())) {
                YYNoticSDK.getInstance().setImageViewResource(noticID, R.id.id_play, R.drawable.auto_type_screen);
                YYNoticSDK instance3 = YYNoticSDK.getInstance();
                instance3.setTextViewText(noticID, R.id.id_name, MyApp.getContext().getString(R.string.mb25) + autoBean2.getAutoTypeDetail());
                YYNoticSDK.getInstance().setTextViewText(noticID, R.id.id_repeat, autoBean2.getAutoName());
            }
        }
    }
}
